﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IQKS.AWP.BusinessAccessLayer;
using IQKS.AWP.BusinessObject;
using System.IO;
using System.Web.Security;
using SFA;
using System.Configuration;
using System.Text.RegularExpressions;
public partial class Common_EditRegisterdPage : System.Web.UI.Page
{

    DataTable tb = new DataTable();
    DataRow dr;
    int tbcountryid = 1;
    string profilepicnamefromdb = string.Empty;
    string profileresumefromdb = string.Empty;
    Int32 FileLimitSize = Convert.ToInt32(ConfigurationManager.AppSettings["FileLimitSize"].ToString());

    #region events
    public string CVPath = ConfigurationSettings.AppSettings["TempCv"];
    public string TempDocumentPathExtention = ConfigurationSettings.AppSettings["ImageFileType"];
    public string TempDocumentPath = ConfigurationSettings.AppSettings["TempProfilePic"];


    public string DocumentPath = ConfigurationSettings.AppSettings["ProfilePic"];
    public string ConfigReqPayString = ConfigurationSettings.AppSettings["ReqPayString"];
    public string ConfigPaymentpath = ConfigurationSettings.AppSettings["Paymentpath"];
    public string CVPathRegistered = ConfigurationSettings.AppSettings["CvPath"];
    

    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {


            Guid UserId = new Guid(Convert.ToString(Session["CandidateUserID"]));


            int cid = Convert.ToInt32(Session["CandidateID"]);
            ViewState["dtWorkExp"] = null;
            lblFormat.InnerText = "* Acceptable file formats: " + Convert.ToString(ConfigurationManager.AppSettings["ImageFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
            lblResume.InnerText = "* Acceptable file formats: " + Convert.ToString(ConfigurationManager.AppSettings["ResumeFileType"]).Replace("|", ",") + Convert.ToString(ConfigurationManager.AppSettings["FileSize"]);
           
            LoadBindData();
            GetCandidateDetailsDataSet(UserId, cid);

            mvwCandidateReg.ActiveViewIndex = 0;
            btnPervious.Visible = false;
            btnFinish.Visible = false;
         //   rbtCandType.SelectedIndex = 0;
           // rbtCandType_SelectedIndexChanged(sender, null);
            mnAccrd_MenuItemClick(sender, null);

            //int cid = 1;

            //Session["CandidateID"] = cid;
            //Session["Amount"] = txtHiden.Text;
            
        }
    }

    private void LoadBindData()
    {
        //--------
        ActivityMasterBAL objActMstBAL = new ActivityMasterBAL();
        DataSet objjActMstDs = new DataSet();

        objjActMstDs = objActMstBAL.GetActivityByActivityType("ACCREDITATIONTYPE");
        CommonUtility.BindDropDown(ref ddlAccreType, objjActMstDs, "ActivityName", "ActivityCode");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlAccreType);
        



        objjActMstDs = objActMstBAL.GetActivityByActivityType("CANDIDATETYPE");
        CommonUtility.BindRadioButtonList(ref rbtCandType, objjActMstDs, "ActivityName", "ActivityCode");

        objjActMstDs = objActMstBAL.GetCountryMasterActive();
        CommonUtility.BindDropDown(ref ddlNationality, objjActMstDs, "CountryName", "CountryID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlNationality);

        //objjActMstDs = objActMstBAL.GetActivityByActivityType("NATIONALIT");
        //CommonUtility.BindDropDown(ref ddlNationality, objjActMstDs, "ActivityName", "ActivityID");
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlNationality);

        objjActMstDs = objActMstBAL.GetActivityByActivityType("GRADUATION");
        CommonUtility.BindDropDown(ref ddlGraduation, objjActMstDs, "ActivityName", "ActivityID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlGraduation);

        //objjActMstDs = objActMstBAL.GetActivityByActivityType("SPECIALIZATION");
        //CommonUtility.BindDropDown(ref ddlSpecialization, objjActMstDs, "ActivityName", "ActivityID");
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlSpecialization);

        objjActMstDs = objActMstBAL.GetActivityByActivityType("QUALIFICATIONSTATUS");
        CommonUtility.BindDropDown(ref ddlQuliStatus, objjActMstDs, "ActivityName", "ActivityID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlQuliStatus);


        objjActMstDs = objActMstBAL.GetCountryMasterActive();

        CommonUtility.BindDropDown(ref ddlCountry, objjActMstDs, "CountryName", "CountryID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlCountry);

        CommonUtility.BindDropDown(ref ddlhCountryCode, objjActMstDs, "CountryTelCode", "CountryID");
        CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlhCountryCode);

        //CommonUtility.BindDropDown(ref ddlMCountryCode, objjActMstDs, "CountryTelCode", "CountryID");
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlMCountryCode);

        DataView objDv = new DataView();
        //DataTable uniqueCols = objjActMstDs.Tables[0].DefaultView.ToTable(true, "CountryTelCode");

        var lselColumns = new[] { "CountryTelCode" };
        DataTable uniqueCols = objjActMstDs.Tables[0].DefaultView.ToTable(true, lselColumns);
        objDv = uniqueCols.DefaultView;
        objDv.Sort = "CountryTelCode ASC";



        CommonUtility.BindDropDown(ref ddlWCountryCode, objDv, "CountryTelCode", "CountryTelCode");
       // CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlWCountryCode);
        CommonUtility.AddSelectToDDLWithOnlySelect(ref ddlWCountryCode);

        CommonUtility.BindDropDown(ref ddlOCountryCode, objDv, "CountryTelCode", "CountryTelCode");
       // CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlOCountryCode);
        CommonUtility.AddSelectToDDLWithOnlySelect(ref ddlOCountryCode);

        CommonUtility.BindDropDown(ref ddlMCountryCode, objDv, "CountryTelCode", "CountryTelCode");
       // CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlMCountryCode);
        CommonUtility.AddSelectToDDLWithOnlySelect(ref ddlOCountryCode);

        LanugageMasterBAL objLangMstBAL = new LanugageMasterBAL();
        objjActMstDs = objLangMstBAL.GetLanguageMasterActive();
        CommonUtility.BindCheckBoxList(ref chkLanguage, objjActMstDs, "LanguageName", "LanguageID");

        ddlNoYearCurrentRole.DataSource = Enumerable.Range(0, 50).ToList();
        ddlNoYearCurrentRole.DataBind();
       // CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlNoYearCurrentRole);
        CommonUtility.AddSelectToDropDownWithMinues(ref ddlNoYearCurrentRole);

        //ddlNoResearchYearCurrentRole.DataSource = Enumerable.Range(0, 50).ToList();
        //ddlNoResearchYearCurrentRole.DataBind();
        //CommonUtility.AddSelectToDropDownAsEmptyValue(ref ddlNoResearchYearCurrentRole);

        ddlNoModeratorYearExp.DataSource = Enumerable.Range(0, 50).ToList();
        ddlNoModeratorYearExp.DataBind();
        CommonUtility.AddSelectToDropDownWithMinues(ref ddlNoModeratorYearExp);

        ddlRLExperience.DataSource = Enumerable.Range(0, 50).ToList();
        ddlRLExperience.DataBind();
        CommonUtility.AddSelectToDropDownWithMinues(ref ddlRLExperience);


    }
    protected void rbtCandType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbtCandType.SelectedValue.ToUpper() == "INDEPENDENT")
        {
           // txtMarketResearchCompany.Text = string.Empty;
            trCompanyName.Visible = false;
            trCompanySpace.Visible = false;


        }
        else if (rbtCandType.SelectedValue.ToUpper() == "CORPORATE")
        {
            trCompanyName.Visible = true;
            trCompanySpace.Visible = true;

        }

    }
    protected void mnAccrd_MenuItemClick(object sender, MenuEventArgs e)
     {
        int intActiveIndex;
        
        if (e != null)
        {
            mvwCandidateReg.ActiveViewIndex = Int32.Parse(e.Item.Value);
        }

        intActiveIndex = mvwCandidateReg.ActiveViewIndex;

        switch (intActiveIndex)
        {
            case 0:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
             
                btnPervious.Visible = false;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 1:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
               // mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 2:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
               // mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 3:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
               // mainMenu.Items[4].Enabled = false;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                break;
            case 4:
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
              //  mainMenu.Items[4].Enabled = true;
                btnPervious.Visible = true;
                btnNext.Visible = false;
                btnFinish.Visible = true;
                break;
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (Page.IsValid == true)
        {
            switch (mvwCandidateReg.ActiveViewIndex)
            {
                case 0:
                    mvwCandidateReg.ActiveViewIndex = 1;
                    btnPervious.Visible = true;
                    btnNext.Visible = true;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;
                    mainMenu.Items[3].Enabled = false;
                 
                    break;
                case 1:
                    mvwCandidateReg.ActiveViewIndex = 2;
                    btnPervious.Visible = true;
                    btnNext.Visible = true;
                    btnFinish.Visible = false;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;
                    mainMenu.Items[3].Enabled = false;
                   
                    if (rdbUploadpic1.Checked)
                    {
                      //  string check =Convert.ToString( fuUploadPic.PostedFile);
                        TempFileSave("PROFILE");
                        //if(check=="")
                        //if (fuUploadPic.PostedFile == null)
                        //{ profilepicnamefromdb = ""; }
                        //else { TempFileSave("PROFILE"); }
                    }
                    else
                    { profilepicnamefromdb = Convert.ToString(ViewState["profiepicdb"]); }
                   
                   // if (fuUploadPic.PostedFile == null)
                   // {
                   //     if(rdbUploadpic2.Checked)
                   //     {  profilepicnamefromdb=Convert.ToString(ViewState["profiepicdb"]);}
                   //     else
                   //     { profilepicnamefromdb="";}

                   // }
                   // //work here for the postfile null
                   //// string serverFileName = Path.GetFileName(fuUploadPic.PostedFile.FileName);
                   // else //(fuUploadPic.PostedFile.FileName !="")                  
                   // {
                   //     TempFileSave("PROFILE");
                   // }

                    break;
                case 2:
                    Boolean expVld = ChkWorkExperience();
                    if (expVld)
                    {
                        mvwCandidateReg.ActiveViewIndex = 3;
                        btnPervious.Visible = true;
                        btnNext.Visible = false;
                        btnFinish.Visible = true;
                        mainMenu.Items[0].Enabled = true;
                        mainMenu.Items[1].Enabled = true;
                        mainMenu.Items[2].Enabled = true;
                        mainMenu.Items[3].Enabled = true;

                        if (rdbResume1.Checked)
                        {

                            TempFileSave("CV");

                        }
                        else
                        { profileresumefromdb = Convert.ToString(ViewState["UploadResume"]); }

                        // if (fuResume.PostedFile.FileName != "")
                        //{
                        //    TempFileSave("CV");
                        //}
                        PreviewDetail();
                    }
                    else
                    {
                        Response.Write("<script>alert('Add Work Experience');</script>");
                    }
                    break;
                case 3:
                 
                    btnPervious.Visible = true;
                    btnNext.Visible = false;
                    btnFinish.Visible = true;
                    mainMenu.Items[0].Enabled = true;
                    mainMenu.Items[1].Enabled = true;
                    mainMenu.Items[2].Enabled = true;
                    mainMenu.Items[3].Enabled = true;
                  
                   
                    break;
            }
        }
    }
    protected void btnPervious_Click(object sender, EventArgs e)
    {
        switch (mvwCandidateReg.ActiveViewIndex)
        {
            case 1:
                mvwCandidateReg.ActiveViewIndex = 0;
                btnPervious.Visible = false;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
               
                break;
            case 2:
                mvwCandidateReg.ActiveViewIndex = 1;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
               
                break;
            case 3:
                mvwCandidateReg.ActiveViewIndex = 2;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = false;
              
                break;
            case 4:
                mvwCandidateReg.ActiveViewIndex = 3;
                btnPervious.Visible = true;
                btnNext.Visible = true;
                btnFinish.Visible = false;
                mainMenu.Items[0].Enabled = true;
                mainMenu.Items[1].Enabled = true;
                mainMenu.Items[2].Enabled = true;
                mainMenu.Items[3].Enabled = true;
              
                break;
        }
    }

    private DataSet GetCandidateDetailsDataSet(Guid Id, int cid)
    {
        DataSet objDs=null;
        try
        {
            objDs = new UserMasterBAL().GetCandidateDetails(Id, cid);

            GetCandidateData(objDs.Tables[0]);
            if (objDs.Tables[0].Rows[0]["ProfilePicturePath"] != null)
            {
                string profilepicturepath1=string.Empty;
                string profilepicpath = Convert.ToString(objDs.Tables[0].Rows[0]["ProfilePicturePath"]);
                ViewState["profiepicdb"] = profilepicpath;
                string[] profilesplit = profilepicpath.Split('.');
                for (int i = 0; i < profilesplit.Count()-1; i++)
                {
                    profilepicturepath1 += profilesplit[i]+".";
                }
              //  profilepicturepath1.Substring(0, profilepicturepath1.Length - 1);
              //  profilepicturepath1.Remove(profilepicturepath1.Length - 2);
            }
            ViewState["UploadResume"] = Convert.ToString(objDs.Tables[0].Rows[0]["CVPath"]);
            if (objDs.Tables[1].Rows.Count != 0)
            {
                DataTable viewtable = new DataTable();
                viewtable = (DataTable)objDs.Tables[1];
               // viewtable.Columns.Remove("");
                //viewtable.Columns.Remove("UserID");
                //viewtable.Columns.Remove("UserID1");
                //viewtable.Columns.Remove("RoleInCompany1");
                //viewtable.Columns.Remove("NumberOfYearRole1");
                //viewtable.Columns.Remove("Remarks1");
                //viewtable.Columns.Remove("CompanyName1");
                //viewtable.Columns.Remove("NumberOfYearResearchRole1");

                ViewState["companydetails"] = viewtable;


               // ViewState["companydetails"] = (DataTable)objDs.Tables[1];
            }
            GetUsersCompany(objDs.Tables[1]);


            string strStatuaID = "";// txtStatusID.Text.Trim();
            //int intStatusID = Convert.ToInt32(StatuaID);

            int intStatusID = (int)objDs.Tables[0].Rows[0]["StatusID"];
            if (intStatusID == 1 || intStatusID == 2 || intStatusID == 23)
            {
               // mainMenu.Items.Remove(mainMenu.Items[1]);
                btnNext.Visible = false;
                btnPervious.Visible = false;
                btnFinish.Visible = false;
            }
            else if (intStatusID == 3)
            {
                //tblAccreditation.Visible = true;
               // tblAccreditationPaymentDetails.Visible = false;
                btnNext.Visible = true;
                btnPervious.Visible = false;
                btnFinish.Visible = false;
                GetCandidatePayment(objDs.Tables[2]);
            }
            else if (intStatusID == 4)
            {
               // tblAccreditation.Visible = false;
                //tblAccreditationPaymentDetails.Visible = true;
                btnNext.Visible = true;
                btnPervious.Visible = true;
                btnFinish.Visible = false;
                GetCandidatePaymentDetails(objDs.Tables[3]);
            }
            string AccrediationName = Convert.ToString(objDs.Tables[0].Rows[0]["AccrediationType"]);
            if (AccrediationName != "")
            {
                ddlAccreType.SelectedIndex = ddlAccreType.Items.IndexOf(ddlAccreType.Items.FindByText(AccrediationName));
               
            }
            else
            {
                ddlAccreType.ClearSelection();
            }

            string CandidateType = Convert.ToString(objDs.Tables[0].Rows[0]["CandidateType"]);
            if (CandidateType == "Independent")
            {
                rbtCandType.Items.FindByText(CandidateType).Selected=true;
                txtMarketResearchCompany.Text = string.Empty;
                trCompanyName.Visible = false;
                trCompanySpace.Visible = false;
            }
            else
            {
                rbtCandType.SelectedIndex = 0;
                trCompanyName.Visible = true;
                trCompanySpace.Visible = true;
               txtMarketResearchCompany.Text = Convert.ToString(objDs.Tables[0].Rows[0]["CompanyName"]);

            }
           
           TextBoxEmailID.Text = Convert.ToString(objDs.Tables[0].Rows[0]["Email"]);
           txtFirstName.Text = Convert.ToString(objDs.Tables[0].Rows[0]["FirstName"]);
           txtMiddleName.Text = Convert.ToString(objDs.Tables[0].Rows[0]["MiddleName"]);
           txtLastName.Text = Convert.ToString(objDs.Tables[0].Rows[0]["LastName"]);
          //  profilepic
           txtDOB.Text = Convert.ToString(objDs.Tables[0].Rows[0]["DOB"]);
            //gender
           
                string Nationality = Convert.ToString(objDs.Tables[0].Rows[0]["NationalityName"]);
            if (AccrediationName != "")
            {
                ddlNationality.SelectedIndex = ddlNationality.Items.IndexOf(ddlNationality.Items.FindByText(Nationality));
               
            }
            else
            {
                ddlNationality.ClearSelection();
            }

            
            //
            string[] languagelist=(Convert.ToString(objDs.Tables[0].Rows[0]["LanguageList"])).Split(',');

           // chkLanguage.Items
            //foreach (string item in languagelist)
            //{
            //    chkLanguage.Items[chkLanguage.Items.IndexOf(chkLanguage.Items.FindByText(item))].Selected = true;
            //}
            for (int j = 0; j < languagelist.Count(); j++)
            {
                for (int i = 0; i < chkLanguage.Items.Count; i++)
                {
                    if (chkLanguage.Items[i].ToString() == languagelist[j].Trim())
                    {
                        //chkLanguage.SetItemChecked(i, true);
                        chkLanguage.Items[i].Selected = true;
                    }
                }
            }

            


           txtContactAdd.Text = Convert.ToString(objDs.Tables[0].Rows[0]["ContactAddress"]);
          
           string CountryName = Convert.ToString(objDs.Tables[0].Rows[0]["CountryName"]);
           if (CountryName != "")
           {
               ddlCountry.SelectedIndex = ddlCountry.Items.IndexOf(ddlCountry.Items.FindByText(CountryName));

           }
           else
           {
               ddlCountry.ClearSelection();
           }

           txtState.Text = Convert.ToString(objDs.Tables[0].Rows[0]["StateName"]);
           txtZip.Text = Convert.ToString(objDs.Tables[0].Rows[0]["ZipCode"]);
                
           string workphoneno = Convert.ToString(objDs.Tables[0].Rows[0]["PhoneNo"]);
           string[] workphonenoparts = workphoneno.Split('-');
            
           ddlWCountryCode.SelectedIndex = ddlWCountryCode.Items.IndexOf(ddlWCountryCode.Items.FindByText(workphonenoparts[0]));
           txtWStdCode.Text = workphonenoparts[1];
           txtWPhone.Text = workphonenoparts[2];
         
           string Mobileno = Convert.ToString(objDs.Tables[0].Rows[0]["MobileNo"]);
         
            string[] Mobilenoparts = Mobileno.Split('-');
            ddlMCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByText(Mobilenoparts[0]));

           txtMPhone.Text = Mobilenoparts[1];
          
           string Otherphoneno = Convert.ToString(objDs.Tables[0].Rows[0]["OtherPhoneNo"]);
           string[] Otherphonenoparts = Otherphoneno.Split('-');
        
           ddlOCountryCode.SelectedIndex = ddlOCountryCode.Items.IndexOf(ddlOCountryCode.Items.FindByText(Otherphonenoparts[0]));

           txtOStdCode.Text = Otherphonenoparts[1];
           txtOPhone.Text = Otherphonenoparts[2];

         
            
            string GraduationName = Convert.ToString(objDs.Tables[0].Rows[0]["GraduationType"]);
            ddlGraduation.SelectedIndex=ddlGraduation.Items.IndexOf(ddlGraduation.Items.FindByText(GraduationName));
           txtSpecialization.Text = Convert.ToString(objDs.Tables[0].Rows[0]["QualificationSpecialization"]);
           txtUniversity.Text = Convert.ToString(objDs.Tables[0].Rows[0]["University"]);
           
            string GraduStatus = Convert.ToString(objDs.Tables[0].Rows[0]["QualificationStatus"]);
            ddlQuliStatus.SelectedIndex = ddlQuliStatus.Items.IndexOf(ddlQuliStatus.Items.FindByText(GraduStatus));

            //gridviewcompany
            //uploadresume







            

        }
        catch (Exception exception)
        {
            exception.AddErrorToLog(); //throw new ApplicationException(exception.Message);
        }
        return objDs;
    }
    public void GetCandidatePaymentDetails(DataTable DtGetCandidatePaymentDetailsData)
    {
        string tdCandidateID = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["CandidateID"]);
       string tdPaymentAmount = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["PaymentAmount"]);
       string tdPaymentDate = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["PaymentDate"]);
      string tdTxnId = Convert.ToString(DtGetCandidatePaymentDetailsData.Rows[0]["TxnId"]);
    }
    public void GetCandidatePayment(DataTable DtGetCandidatePaymentData)
    {
       string tdFees = Convert.ToString(DtGetCandidatePaymentData.Rows[0]["FeesAmt"]);
      string txtHiden = Convert.ToString(DtGetCandidatePaymentData.Rows[0]["FeesAmt"]);
    }
    private void GetUsersCompany(DataTable DtUsersCompanyData)
    {
        gvUser.DataSource = (DtUsersCompanyData);
        gvUser.DataBind();
    }

    public void GetCandidateData(DataTable DtCandidateData)
    {

        tdAccreditationType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["AccrediationType"]);
        string strCandidateType = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        tdCandidateType.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["CandidateType"]);
        if (strCandidateType == "Independent")
        {
           // trMarketReserachCompany.Visible = false;
        }
        else
        {
           // trMarketReserachCompany.Visible = true;
           string tdMarketReserachCompany = Convert.ToString(DtCandidateData.Rows[0]["CompanyName"]);
        }


        tdEmail.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Email"]);
        tdFirstName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["FirstName"]);
        // tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);

        string middlename = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);
        if (middlename == "")
        {
            tdMiddleName.InnerHtml = "&nbsp;&nbsp;-";

        }
        else
        {
            tdMiddleName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MiddleName"]);

        }

        tdLastName.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["LastName"]);
        //string strDOB = Convert.ToString(DtCandidateData.Rows[0]["DOB"]);
        //string dateOnlyString = strDOB.ToShortDateString();
        tdDOB.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["conDOB"]);
        string strGender = Convert.ToString(DtCandidateData.Rows[0]["Gender"]);
        //if(strGender=="M")
        //{
        //    tdGender.InnerHtml = "Male";
        //}
        //else
        //{
        //    tdGender.InnerHtml = "Female";
        //}

        //tdGender.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Gender"]);

        //tdNationalityID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["NationalityID"]);
       string tdNationality = Convert.ToString(DtCandidateData.Rows[0]["NationalityName"]);
       string tdContectAddress = Convert.ToString(DtCandidateData.Rows[0]["ContactAddress"]);
       string tdCountry = Convert.ToString(DtCandidateData.Rows[0]["CountryName"]);
        string tdState = Convert.ToString(DtCandidateData.Rows[0]["StateName"]);
       string tdZipCode = Convert.ToString(DtCandidateData.Rows[0]["ZipCode"]);

        // tdHomePhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        string otherphoneno = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);
        string[] otherphonenoparts = otherphoneno.Split('-');
        if (otherphonenoparts[0] == "" || otherphonenoparts[1] == "" || otherphonenoparts[2] == "")
        { string tdHomePhoneNo = "&nbsp;&nbsp;-"; }
        else
        {
           string tdHomePhoneNo = Convert.ToString(DtCandidateData.Rows[0]["OtherPhoneNo"]);

        }

        // tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        string phoneno = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);
        string[] phonenoparts = phoneno.Split('-');
        if (phonenoparts[0] == "" || phonenoparts[1] == "" || phonenoparts[2] == "")
        { string tdWorkPhoneNo = "&nbsp;&nbsp;-"; }
        else
        {
           string tdWorkPhoneNo = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        }


        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string mobileno = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);
        string[] mobparts = mobileno.Split('-');
        if (mobparts[1] == "")
        { tdMobileNo.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        {
          string tdMobileNo = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);

        }



        //tdWorkPhoneNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["PhoneNo"]);

        // tdMobileNo.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["MobileNo"]);

        //tdGraduationID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationID"]);
        tdGraduation.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["GraduationType"]);
        //tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdSpecialization.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["Specialisation"]);
        tdUniversity.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["University"]);
        //tdQualificationStatusID.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatusID"]);
        tdStatus.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["QualificationStatus"]);
       string  txtStatusID = Convert.ToString(DtCandidateData.Rows[0]["StatusID"]);

        string strProfilePath = Convert.ToString(DtCandidateData.Rows[0]["ProfilePicturePath"]);
        if (strProfilePath == "")
        {
            Image1.ImageUrl = "~/Images/Unknown2.jpg";
            Image3.ImageUrl = "~/Images/Unknown2.jpg";


        }
        else
        {
            Image1.ImageUrl = DocumentPath + '/' + strProfilePath;
            Image3.ImageUrl = DocumentPath + '/' + strProfilePath;
        }
        tdRegNumber.InnerHtml = Convert.ToString(DtCandidateData.Rows[0]["RegistrationNo"]);
        string tdCandidateLanguageDetail = Convert.ToString(DtCandidateData.Rows[0]["LanguageList"]);
        //bjp add for extra 5 fields
        txtProCurrentRole.Text = Convert.ToString(DtCandidateData.Rows[0]["ProCurrentRole"]);
        txtProExperience.Text = Convert.ToString(DtCandidateData.Rows[0]["ProExperience"]);
        txtProfQualitative1.Text = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative1"]);
        txtProfQualitative2.Text = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative2"]);
        txtProfQualitative3.Text = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative3"]);
        txtProfQualitative4.Text = Convert.ToString(DtCandidateData.Rows[0]["ProfQualitative4"]);
        //----
        string strPath = string.Empty;
        string strCvTitle = Convert.ToString(DtCandidateData.Rows[0]["CVPath"]);
       // string strAuthority = HttpContext.Current.Request.Url.Authority;
        string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;

        string strUCvpath = CVPath.Remove(0, 1);
        
        strPath =  strAuthority + strUCvpath + strCvTitle;
       string strPathPreResume = string.Empty;
       string strPreDownResume = CVPathRegistered.Remove(0, 1);
       strPathPreResume = strAuthority + strPreDownResume + strCvTitle;
        tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('" + strPath + "')>" + "<b>Click Here</b>" + "</a>";
        tdPreviousResumeView.InnerHtml = "<a href=javascript:onClickLink('" + strPathPreResume + "')>" + "<b>Download Previous Resume</b>" + "</a>";
    }
    protected void btnAddWorkExp_Click(object sender, EventArgs e)
    {
        if(Page.IsValid ==   true)
        { 
            //Add wrok experience

            if (ViewState["companydetails"] != null)
            {
                tb = (DataTable)ViewState["companydetails"];
                dr = tb.NewRow();
                dr["CandidateCompanyID"] = (tb.Rows.Count + 1);
                dr["CompanyName"] = txtCompanyName.Text;
                dr["TypeOfCompany"] = TxtTypeOfCompany.Text;
                dr["RoleInCompany"] = txtCurrentRole.Text;
                dr["NumberOfYearRole"] = ddlNoYearCurrentRole.SelectedValue.Trim();
                dr["NumberOfYearModeratorRole"] = ddlNoModeratorYearExp.SelectedValue.Trim();
                dr["NumberOfYearResearchRole"] = ddlRLExperience.SelectedValue.Trim();
                dr["Remarks"] = txtRemark.Text;
                tb.Rows.Add(dr);
                gvUser.DataSource = tb;
                gvUser.DataBind();
                clearexperiencefield();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Work Experience added Successfully.');", true);


                CompanyDetailsGV.Visible = true;
                gvUser.Visible = true;
                ViewState["companydetails"] = tb;
            }
            else
            {
               // tb = ViewState["companydetails"] as DataTable;
                //DataTable tb1 = new DataTable();
                AddWorkExperience(txtCompanyName.Text.Trim(),TxtTypeOfCompany.Text.Trim(), txtCurrentRole.Text.Trim(), ddlNoYearCurrentRole.SelectedValue.Trim(),ddlNoModeratorYearExp.SelectedValue.Trim(), ddlRLExperience.SelectedValue.Trim(), txtRemark.Text.Trim());
                CompanyDetailsGV.Visible = true;
                gvUser.Visible = true;
                gvUser.DataSource = (DataTable)ViewState["companydetails"];
                gvUser.DataBind();
               // BindWorkExperience();
                clearexperiencefield();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Work Experience added Successfully.');", true);

            }

            //if (ddlNoYearCurrentRole.SelectedItem.Text == "0")
            //{ dr["NumberOfYearRole"] = "0"; }
            //else
            //{
            //}
            //if (ddlNoResearchYearCurrentRole.SelectedItem.Text == "0")
            //{ dr["NumberOfYearResearchRole"] = "0"; }
            //else
            //{
            //    dr["NumberOfYearResearchRole"] = ddlNoYearCurrentRole.SelectedItem.Text;
            //}
           
            // companydetails.Visible = true;
          
            //txtCompanyName.Text = "";
            //txtCurrentRole.Text = "";
            //txtRemark.Text = "";
            //ddlNoYearCurrentRole.SelectedIndex = 0;
            //ddlNoResearchYearCurrentRole.SelectedIndex = 0;
           


            //AddWorkExperience(txtCompanyName.Text.Trim(), txtCurrentRole.Text.Trim(), ddlNoYearCurrentRole.SelectedValue.Trim(),ddlNoResearchYearCurrentRole.SelectedValue.Trim(), txtRemark.Text.Trim());
            //BindWorkExperience();
        }

    }

    private void clearexperiencefield()
    {
        txtCompanyName.Text = "";
        txtCurrentRole.Text = "";
        txtRemark.Text = "";
        ddlNoYearCurrentRole.SelectedIndex = 0;
        ddlNoModeratorYearExp.SelectedIndex = 0;
        ddlRLExperience.SelectedIndex = 0;
    }

    private void BindWorkExperience() 
    {
       // gvAddWorkExp.DataSource = (DataTable)ViewState["companydetails"];
      //  gvAddWorkExp.DataBind();
    }

    private Boolean ChkWorkExperience()
    {
        DataTable dtWorkExp;

        if (ViewState["companydetails"] == null)
        {
            return false;
        }
        else
        {
            dtWorkExp = (DataTable)ViewState["companydetails"];

            var querySum = (from qs in dtWorkExp.AsEnumerable()
                            select qs).Count();

            if (querySum > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

    private void AddWorkExperience(string strCompnayName,string strTypeOfCompany, string strCurrentRole, string strNoYearCurrentRole,string strNoModeratorYears,string strNoResearchYearCurrentRole, string strRemarks)
    {
        DataTable dtWorkExp ;

        if (ViewState["companydetails"] == null)
        {
            dtWorkExp = new DataTable();
            dtWorkExp.Columns.Add("CandidateCompanyID");
            dtWorkExp.Columns.Add("CompanyName");
            dtWorkExp.Columns.Add("TypeOfCompany");
            dtWorkExp.Columns.Add("RoleInCompany");
            dtWorkExp.Columns.Add("NumberOfYearRole");
            dtWorkExp.Columns.Add("NumberOfYearModeratorRole");
            dtWorkExp.Columns.Add("NumberOfYearResearchRole");
            dtWorkExp.Columns.Add("Remarks");
        }
        else
        {
            dtWorkExp = (DataTable)ViewState["companydetails"];
        }


        
        DataRow drWorkExp = dtWorkExp.NewRow();

        drWorkExp["CandidateCompanyID"] = (dtWorkExp.Rows.Count + 1);
        drWorkExp["CompanyName"] = strCompnayName;
        drWorkExp["TypeOfCompany"] = strTypeOfCompany;
        drWorkExp["RoleInCompany"] = strCurrentRole;

        drWorkExp["NumberOfYearRole"] = strNoYearCurrentRole;
        drWorkExp["NumberOfYearModeratorRole"] = strNoModeratorYears;
        drWorkExp["NumberOfYearResearchRole"] = strNoResearchYearCurrentRole;
        drWorkExp["Remarks"] = strRemarks;

        var querySum = (from qs in dtWorkExp.AsEnumerable()
                        where qs.Field<string>("CompanyName") == strCompnayName
                        select qs).Count();

        if (querySum <= 0)
        {
            dtWorkExp.Rows.Add(drWorkExp);
            ViewState["companydetails"] = dtWorkExp;
        }
        else
        {
            Response.Write("The Record already exists in the table");
        }
    }


    protected void gvAddWorkExp_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        //int intCompanyExpID = (int)gvAddWorkExp.DataKeys[e.RowIndex].Value;
        //string strStatus = Convert.ToString(gvAddWorkExp.Rows[e.RowIndex].Cells[2].Text) == "Active" ? "DELETE" : "ACTIVE";
        //DeleteLanguage(intLanguageID, strStatus);
        //GetData();
        ((DataTable)ViewState["dtWorkExp"]).Rows.RemoveAt(e.RowIndex);
        BindWorkExperience();

    }


    protected void gvAddWorkExp_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lnBtn = (LinkButton)e.Row.FindControl("lnkDelete");
            lnBtn.Attributes.Add("onclick", "javascript:return " + "confirm('Are you sure you want to delete " + DataBinder.Eval(e.Row.DataItem, "CompanyName") + " Company Name?')");
        }
    }
    protected void gvAddWorkExp_RowEditing(object sender, GridViewEditEventArgs e)
    {
      
    }
    protected void btnFinish_Click(object sender, EventArgs e)
    {
        if(Page.IsValid == true)
        {
            string strReturnValue;
            CandidateMasterBO objCandidateMasterBO = new CandidateMasterBO();
            UserMasterBAL objUserMasterBAL = new UserMasterBAL();

            UserMasterBO objUserMasterBO = new UserMasterBO();
            objUserMasterBO.ApplicationName = "/";
           
            objUserMasterBO.RoleName = ddlAccreType.SelectedValue;
            objUserMasterBO.SetMethod = "UPDATE";
            objCandidateMasterBO.AccrediationTypeCode = ddlAccreType.SelectedValue;
            objCandidateMasterBO.CandidateTypeCode = rbtCandType.SelectedValue;
            if (rbtCandType.SelectedValue == "CORPORATE")
            {
                objCandidateMasterBO.MarketResearchCompany = txtMarketResearchCompany.Text;
            }
            else
            {
                objCandidateMasterBO.MarketResearchCompany = string.Empty;
            }
            
            //TAB 2
            objUserMasterBO.EmailID = "";// txtEmail.Text.Trim();
            objUserMasterBO.Password = "";// hdnPassword.Value;
            objUserMasterBO.SecretQuestion ="";// txtQuestion.Text.Trim();
            objUserMasterBO.SecretAnswer = "";// txtAnswer.Text.Trim();
            objUserMasterBO.CreatedDate =  System.DateTime.Now;

            //TAB 3
            objUserMasterBO.EmailID = TextBoxEmailID.Text;
            objUserMasterBO.FirstName = txtFirstName.Text.Trim();
            objUserMasterBO.LastName = txtLastName.Text.Trim();
            objUserMasterBO.MiddleName = txtMiddleName.Text.Trim();
            //TODO
            //string strDate=Convert.ToString(txtDOB.Text.Trim());
            //DateTime date = Convert.ToDateTime(txtDOB.Text.Trim());
            //objUserMasterBO.DOBirth = CommonUtility.ConvertDateToMMddyyyy(txtDOB.Text.Trim());
            objUserMasterBO.DOBirth = "01/01/2001";
            //TODO
            if (rdbUploadpic2.Checked)
            { objUserMasterBO.ProfilePicturePath = Convert.ToString(ViewState["profiepicdb"]); }
            else
            {
                objUserMasterBO.ProfilePicturePath = Path.GetFileName(hdnUploadPic.Value);
            }
            //objUserMasterBO.Gender = rdbtnGender.SelectedValue;
            objUserMasterBO.Gender = "Male/Female";
            objUserMasterBO.NationalityID = Convert.ToInt16(ddlNationality.SelectedValue);
            objCandidateMasterBO.LanguageList = LanguageList();            
            UsersContactBO objUsersContactBO = new UsersContactBO();
            objUsersContactBO.ContactAddress = txtContactAdd.Text.Trim();
            objUsersContactBO.CountryID = Convert.ToInt16(ddlCountry.SelectedItem.Value);
            if (txtState.Text=="")
            {
                objUsersContactBO.StateName = "-";
            }
            else
            {
                objUsersContactBO.StateName = txtState.Text.Trim();
            }
            
            objUsersContactBO.ZipCode = txtZip.Text.Trim();
            objUsersContactBO.PhoneNo = ddlWCountryCode.SelectedItem.Value + "-" + txtWStdCode.Text.Trim() + "-" + txtWPhone.Text.Trim();
            objUsersContactBO.OtherPhoneNo = ddlOCountryCode.SelectedItem.Value + "-" + txtOStdCode.Text.Trim() + "-" + txtOPhone.Text.Trim();
            objUsersContactBO.MobileNo = ddlMCountryCode.SelectedItem.Value + "-"  + txtMPhone.Text.Trim();
            //TAB 4
            UsersQualificationBO objUsersQualificationBO = new UsersQualificationBO();
            objUsersQualificationBO.GraduationID = Convert.ToInt16(ddlGraduation.SelectedValue);
            objUsersQualificationBO.QualificationSpecialization = txtSpecialization.Text.Trim();
            objUsersQualificationBO.University = txtUniversity.Text.Trim();
            objUsersQualificationBO.QualificationStatusID = Convert.ToInt16(ddlQuliStatus.SelectedValue);
            //bjp add for new 5 fields
            objUsersQualificationBO.ProCurrentRole = txtProCurrentRole.Text.Trim();
            objUsersQualificationBO.ProExperience = txtProExperience.Text.Trim();
            objUsersQualificationBO.ProfQualitative1 = txtProfQualitative1.Text.Trim();
            objUsersQualificationBO.ProfQualitative2 = txtProfQualitative2.Text.Trim();
            objUsersQualificationBO.ProfQualitative3 = txtProfQualitative3.Text.Trim();
            objUsersQualificationBO.ProfQualitative4 = txtProfQualitative4.Text.Trim();
            //-------
            if (((DataTable)ViewState["companydetails"]) == null)
            {
                objUserMasterBO.UserCompanyDetail = "<DocumentElement><Table1><CandidateCompanyID>0</CandidateCompanyID><CompanyName></CompanyName><TypeOfCompany></TypeOfCompany><CurrentRole></CurrentRole><NoYearCurrentRole></NoYearCurrentRole><NoModeratorYearRole></NoModeratorYearRole><NoResearchYearRole></NoResearchYearRole><Remarks></Remarks></Table1></DocumentElement>";
            }
            else
            {
                DataTable dtWorkExp = new DataTable();
                dtWorkExp = (DataTable)ViewState["companydetails"];
                if (dtWorkExp.Rows.Count > 0)
                {
                    objUserMasterBO.UserCompanyDetail = CommonUtility.ConvertDatatableToXML(((DataTable)ViewState["companydetails"]));
                }
                else
                {
                    objUserMasterBO.UserCompanyDetail = "<DocumentElement><Table1><CandidateCompanyID>0</CandidateCompanyID><CompanyName></CompanyName><TypeOfCompany></TypeOfCompany><CurrentRole></CurrentRole><NoYearCurrentRole></NoYearCurrentRole><NoModeratorYearRole></NoModeratorYearRole><NoResearchYearRole></NoResearchYearRole><Remarks></Remarks></Table1></DocumentElement>";
                }
            }
            Int64 cid = Convert.ToInt64(Session["CandidateID"]);
            string uidregisterd = (string)Session["CandidateUserID"];
            if (rdbResume2.Checked)
            { objCandidateMasterBO.CVPath = Convert.ToString(ViewState["UploadResume"]); }
            else
            {
                objCandidateMasterBO.CVPath = Path.GetFileName(hdnResume.Value);
               
            }

            //objCandidateMasterBO.CVPath = Path.GetFileName(hdnResume.Value);

           // string strfilepath = Request.PhysicalApplicationPath + ;
           // File.Delete(strfilepath);

      //      strReturnValue = "";// (string)objUserMasterBAL.SetCandidateMaster(objUserMasterBO, objCandidateMasterBO, objUsersContactBO, objUsersQualificationBO);
      int  intstrReturnValue = (int) objUserMasterBAL.EditRegisterdCandidateMaster(objUserMasterBO, objCandidateMasterBO, objUsersContactBO, objUsersQualificationBO,cid,uidregisterd);
       // strReturnValue = (string)objUserMasterBAL.EditRegisterdCandidateMaster(objUserMasterBO, objCandidateMasterBO, objUsersContactBO, objUsersQualificationBO, cid, uidregisterd);
       if(intstrReturnValue==2)
           UploadedFileMove();
       string script = "window.onload = function(){alert('Candidate Details Successfully Updated..'); window.location = '../Common/RegisterAlready.aspx';  };";
       if (!Page.ClientScript.IsStartupScriptRegistered(this.GetType(), "Redirect"))
       {
           ClientScript.RegisterStartupScript(this.GetType(), "Redirect", script, true);
       }
       

            //Response.Redirect("~/Common/RegisterAlready.aspx", true);

            //MembershipUser User;
            //if (strReturnValue == "SUCCESS")
            //{
            //    User = Membership.GetUser(TextBoxEmailID.Text, false);
            //  //  User.ChangePasswordQuestionAndAnswer("test@12345", "", "");
               
            //   // User.ChangePassword("test@12345", "");
            //    UploadedFileMove();
            //    Session["EmailID"] = TextBoxEmailID.Text.Trim();
            //    Response.Redirect("~/Common/RegisterAlready.aspx", true);
            //    ViewState["dtWorkExp"] = null;
            //}
            //else if (strReturnValue == "EXIST")
            //{

            //    Membership.DeleteUser(TextBoxEmailID.Text.Trim(), true);
            //   // lblMessage.Text = "Activity Type already exists."; //EnrollResources.GetMessage(Message.InsertMessage); //     
            //    ViewState["dtWorkExp"] = null;
            //}
            //else
            //{
               
            //    ViewState["dtWorkExp"] = null;
            //   // lblMessage.Text = "Error while saving record."; //EnrollResources.GetMessage(Message.FailedMessage); // 
            //}


        }
    }

    private int UploadedFileMove()
    {
        int intStatus=0;
        string strProfileFilePath,strResumeFilePath,strbackupfilepath=string.Empty;

        if (hdnUploadPic.Value != "")
        { 
            strProfileFilePath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["ProfilePic"]) + Path.GetFileName(hdnUploadPic.Value));
           if(File.Exists(strProfileFilePath))
            File.Delete(strProfileFilePath);
            File.Move(hdnUploadPic.Value, strProfileFilePath);
          //  File.Replace(hdnUploadPic.Value, strProfileFilePath, strbackupfilepath);
            
        }

        if (hdnResume.Value != "")
        {

            strResumeFilePath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["CvPath"]) + Path.GetFileName(hdnResume.Value));
          if(File.Exists(strResumeFilePath))
            File.Delete(strResumeFilePath);
            File.Move(hdnResume.Value, strResumeFilePath);
        }
        return intStatus;

    }
    protected void cvMobileNoValidation_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (Convert.ToInt64(txtMPhone.Text.Trim()) == 0)
        {
            args.IsValid = false;
            return;
        }
    }
    private string LanguageList()
    {
        string strLanguageList = string.Empty;
        for (int i = 0; i < chkLanguage.Items.Count; i++)
        { 
            if (chkLanguage.Items[i].Selected)
            {
                strLanguageList += chkLanguage.Items[i].Value + ",";
            }
        }
        return strLanguageList.Substring(0, (strLanguageList.Length - 1));
    }


    private int LanguageSelected()
    {
        int intCount = 0;
        for (int i = 0; i < chkLanguage.Items.Count; i++)
        {
            if (chkLanguage.Items[i].Selected)
            {
                intCount = 1;
                return intCount;
            }
        }
        return intCount;
    }

    protected void cstLanguage_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (LanguageSelected() <= 0)
        {
            args.IsValid = false;
            return;
        }
    }

    private int CompanyValidate()
    {
        int intCount = 0;
        if (ViewState["companydetails"] != null)
        {
            DataTable dtWorkExp;
            dtWorkExp = (DataTable)ViewState["companydetails"]; 
            var querySum = (from qs in dtWorkExp.AsEnumerable()
                            where qs.Field<string>("CompanyName") == txtCompanyName.Text.Trim()
                            select qs).Count();

            if (querySum > 0)
            {
                //Response.Write("Company name already exists");
                intCount = 1;
                return intCount;
            }
        }
        return intCount;
    }
    protected void cvAddWorkExp_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //if (CompanyValidate() > 0)
        //{
        //    args.IsValid = false;
        //    return;
        //}
        if (ViewState["vwResumeCmyID"] == null)
        {

            if (CompanyValidate() > 0)
            {
                args.IsValid = false;
                return;
            }
        }
        else
        {
            if (Convert.ToString(ViewState["CompanyNamevalidation"]) == txtCompanyName.Text.Trim())
            {
                args.IsValid = true;
                return;


            }
            else
            {
                if (CompanyValidate() > 0)
                {
                    args.IsValid = false;
                    return;
                }
            }

        }
    }
    protected void cstUploadPic_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (fuUploadPic.PostedFile == null)
       
        {
            if (rdbUploadpic2.Checked)
                return;
            args.IsValid = false;
            //  cstUploadPic.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (fuUploadPic.PostedFile.FileName == "")
            {
                if (rdbUploadpic2.Checked)
                    return;
                args.IsValid = false;
                cstUploadPic.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (fuUploadPic.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (fuUploadPic.PostedFile.ContentLength == 0)
                {
                    if (rdbUploadpic2.Checked)
                        return;
                    args.IsValid = false;
                    cstUploadPic.ErrorMessage = "Select Valid file.";
                    return;
                }
                string pattern = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileName"]);
                Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
                Match match = regex.Match(Path.GetFileNameWithoutExtension(fuUploadPic.FileName));

                if (!match.Success)
                {
                    args.IsValid = false;
                    cstUploadPic.ErrorMessage = Convert.ToString(ConfigurationManager.AppSettings["DocumentFileNameErrorMsg"]);
                    return;
                }
                //int fileSize = fuUploadPic.PostedFile.ContentLength;
                //if (fileSize > (FileLimitSize))
                //{
                //    args.IsValid = false;
                //    cstUploadPic.ErrorMessage = "Image size should not be more than 5 MB.";
                //    return;
                //}

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(fuUploadPic.PostedFile.FileName) == true)
                {
                    /*check void extension are there or not*/
                    if (rdbUploadpic2.Checked)
                        return;
                    if (CommonUtility.CheckExtension(Path.GetExtension(fuUploadPic.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ImageFileType"])) == false)
                    {
                        if (rdbResume2.Checked)
                            return;
                        args.IsValid = false;
                        cstUploadPic.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                }
            }
        }

    }


    protected void cstResume_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (fuResume.PostedFile == null)
        {
            if (rdbResume2.Checked)
                return;
            args.IsValid = false;
            cstResume.ErrorMessage = "Select file to attach.";
            return;
        }
        else
        {
            if (rdbResume2.Checked)
                return;
            if (fuResume.PostedFile.FileName == "")
            {
                args.IsValid = false;
                cstResume.ErrorMessage = "Select file to attach.";
                return;
            }
            else if (fuResume.PostedFile.FileName != "")
            {
                /*check file is valid*/
                if (rdbResume2.Checked)
                    return;
                if (fuResume.PostedFile.ContentLength == 0)
                {
                    args.IsValid = false;
                    cstResume.ErrorMessage = "Select Valid file.";
                    return;
                }

                //int fileSize = fuResume.PostedFile.ContentLength;
                //if (fileSize > (FileLimitSize))
                //{
                //    args.IsValid = false;
                //    cstResume.ErrorMessage = "Resume document size should not be more than 5 MB.";
                //    return;
                //}

                /*Check file name has extension*/
                if (System.IO.Path.HasExtension(fuResume.PostedFile.FileName) == true)
                {

                    /*check void extension are there or not*/
                    if (CommonUtility.CheckExtension(Path.GetExtension(fuResume.PostedFile.FileName), Convert.ToString(ConfigurationManager.AppSettings["ResumeFileType"])) == false)
                    {
                        if (rdbResume2.Checked)
                            return;
                        args.IsValid = false;
                        cstResume.ErrorMessage = "Upload File failed. Select file format as per below.";
                        return;
                    }

                }
            }
        }

    }

    private void TempFileSave(string strFileType)
    {
        string strPath = string.Empty;
        string strFileExt = string.Empty;
        string strFileName = string.Empty;
        
        if (strFileType == "PROFILE")
        {
           
            if (fuUploadPic.HasFile)
            {
                strFileExt = Path.GetExtension(fuUploadPic.PostedFile.FileName);
                strFileName = fuUploadPic.FileName.Replace(Convert.ToString(fuUploadPic.FileName), TextBoxEmailID.Text.Trim());
                strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["TempProfilePic"]));
                //fuUploadPic.FileName.Replace()
                hdnUploadPic.Value = strPath + strFileName + "_ProfilePic" + strFileExt;
                //fuUploadPic.SaveAs(hdnUploadPic.Value);
                CommonUtility.SaveFile(fuUploadPic, strPath, strFileName + "_ProfilePic" + strFileExt);
            }
        
        }
        else if (strFileType == "CV")
        {

            strFileExt = Path.GetExtension(fuResume.PostedFile.FileName);
            string emailnm = TextBoxEmailID.Text.Trim().Replace('.', '_');
            strFileName = fuResume.FileName.Replace(Convert.ToString(fuResume.FileName), emailnm);
            strPath = MapPath(Convert.ToString(ConfigurationManager.AppSettings["TempCv"]));
            hdnResume.Value = strPath + strFileName + "_CV" + strFileExt;
            //fuResume.SaveAs(hdnResume.Value);
            CommonUtility.SaveFile(fuResume, strPath, strFileName + "_CV" + strFileExt);
        }
    }


    protected void csvEmail_ServerValidate(object source, ServerValidateEventArgs args)
    {
           UserMasterBAL objUserMasterBAL = new UserMasterBAL();
           DataSet objDs = new DataSet();
           objDs = objUserMasterBAL.GetCandidateDetailsByEmailID(TextBoxEmailID.Text.Trim());
           if (objDs.Tables[0].Rows.Count > 0)
           {
              // csvEmail.ErrorMessage = "Email id already exists."; 
               args.IsValid = false;
           }      
    }

    private void PreviewDetail()
    {
        tdAccreditationType.InnerHtml = ddlAccreType.SelectedItem.Text;
        tdCandidateType.InnerHtml = rbtCandType.SelectedItem.Text;

        if (rbtCandType.SelectedValue.ToUpper() == "INDEPENDENT")
        {
            trMarketReserach.Visible = false;
            tdMarketResearch.InnerHtml = ""; 
        }
        else
        {
            trMarketReserach.Visible = true;
            tdMarketResearch.InnerHtml = txtMarketResearchCompany.Text;
        }
        string strPath = string.Empty;
        string strFileName = string.Empty;
       // strFileName = Path.GetFileName(hdnUploadPic.Value);
       // strFileName = txtEmail.Text.Trim();
      if(rdbUploadpic2.Checked)
      { strFileName = Convert.ToString(ViewState["profiepicdb"]); }
      else
      {   strFileName = Path.GetFileName(hdnUploadPic.Value);
     }
        if (strFileName=="")
        {
            Image1.ImageUrl ="~/Images/Unknown2.jpg";
        }
        else
        {
            if(rdbUploadpic2.Checked)
                Image1.ImageUrl = DocumentPath + strFileName;
               
            else 
                Image1.ImageUrl = TempDocumentPath + strFileName;
        }



        tdEmail.InnerHtml = TextBoxEmailID.Text.Trim();
       // tdSecretQuestion.InnerHtml = txtQuestion.Text.Trim();
        tdFirstName.InnerHtml = txtFirstName.Text.Trim();
        if (txtMiddleName.Text == "")
        {
            tdMiddleName.InnerHtml = "&nbsp;&nbsp;-";

        }
        else
        {
            tdMiddleName.InnerHtml = txtMiddleName.Text.Trim();
        }
        tdLastName.InnerHtml = txtLastName.Text.Trim();
        


        //tdDOB.InnerHtml = txtDOB.Text.Trim();
        tdGender.InnerHtml = (rdbtnGender.SelectedValue == "M" ? "Male" : "Female");
        tdNationality.InnerHtml = ddlNationality.SelectedItem.Text;
        //tdLanguage.InnerHtml = LanguageList();
        if (txtContactAdd.Text == "")
        { tdContactAddress.InnerHtml = "&nbsp;&nbsp;-"; }
        else
        { tdContactAddress.InnerHtml = txtContactAdd.Text; }

        tdCountry.InnerHtml = ddlCountry.SelectedItem.Text;
        //tdState.InnerHtml = txtState.Text;
        tdZip.InnerHtml = txtZip.Text;

        if(txtWStdCode.Text=="" || txtWPhone.Text=="")
        { 
            tdWorkPhone.InnerHtml="&nbsp;&nbsp;-"; }
        else{
        tdWorkPhone.InnerHtml = (ddlWCountryCode.SelectedItem.Text == "--- Select ---" ? "" : ddlWCountryCode.SelectedItem.Text+ "-" ) + "" + (txtWStdCode.Text == "--- Select ---" ? "" : txtWStdCode.Text + "-" ) + "" + (txtWPhone.Text == "--- Select ---" ? "" : txtWPhone.Text);
        }
        tdMobileNo.InnerHtml = ddlMCountryCode.SelectedItem.Text + "-" + txtMPhone.Text;

         if(txtOStdCode.Text=="" || txtOPhone.Text=="")
         { tdOtherPhone.InnerHtml="&nbsp;&nbsp;-";}
         else{
        tdOtherPhone.InnerHtml = (ddlOCountryCode.SelectedItem.Text == "--- Select ---" ? "" : ddlOCountryCode.SelectedItem.Text + "-") + "" + (txtOStdCode.Text == "--- Select ---" ? "" : txtOStdCode.Text + "-") + "" + (txtOPhone.Text == "--- Select ---" ? "" : txtOPhone.Text);
         }
        tdGraduation.InnerHtml = ddlGraduation.SelectedItem.Text;
        tdSpecialization.InnerHtml = txtSpecialization.Text;
        tdUniversity.InnerHtml = txtUniversity.Text;
        tdStatus.InnerHtml = ddlQuliStatus.SelectedItem.Text;

        //string strAuthority = HttpContext.Current.Request.Url.Authority;
        string strAuthority = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + HttpContext.Current.Request.ApplicationPath;
        
             string strCVPath =string.Empty;
             string strresumename = string.Empty;

        if (rdbResume2.Checked)
        { strCVPath = CVPathRegistered.Remove(0, 1);
        strresumename = Convert.ToString(ViewState["UploadResume"]);
        }
        else
        {  strCVPath = CVPath.Remove(0, 1);
        strresumename = Path.GetFileName(hdnResume.Value);
        }

        strPath =  strAuthority + strCVPath + strresumename; // Path.GetFileName(hdnResume.Value);

        tdUploadResume.InnerHtml = "<a href=javascript:onClickLink('"+ strPath + "')>" + "<b>Click Here</b>" + "</a>";


        if (ViewState["companydetails"] != null)
        {
            DataTable dtWorkExp = new DataTable();
            dtWorkExp = (DataTable)ViewState["companydetails"];
            if (dtWorkExp.Rows.Count > 0)
            {
                trCompanyDetail.Visible = true;
                trCompanyDetailSpace.Visible = true;
                gvCompanyDetails.DataSource = (DataTable)ViewState["companydetails"];
                gvCompanyDetails.DataBind();
                trCompanyDetailHead.Visible = true;
                trCompanyDetailSpace.Visible = true;
            }
            else
            {

                trCompanyDetailHead.Visible = false;
                trCompanyDetailSpace.Visible = false;
                trCompanyDetail.Visible = false;
                trCompanyDetailSpace.Visible = false;
            }

        }
        else
        {
            trCompanyDetailHead.Visible = false;
            trCompanyDetailSpace.Visible = false;
            trCompanyDetail.Visible = false;
            trCompanyDetailSpace.Visible = false;
        }
    }

    protected void hdnUploadPic_ValueChanged(object sender, EventArgs e)
    {

    }
  
    protected void OnLnkDownload_Click(object sender, EventArgs e)
    {
        //LinkButton lnkbtn = sender as LinkButton;
        ////GridViewRow gvrow = lnkbtn.NamingContainer as GridViewRow;
        ////string filePath = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        //Response.ContentType = "image/jpg";
        //Response.AddHeader("Content-Disposition", "attachment;filename=\"" + CVPath + "\"");
        //Response.TransmitFile(Server.MapPath(filePath));
        //Response.End();
        string pathfilename=Path.GetFileName(hdnResume.Value);

        string strPath = CVPath + pathfilename;
        //string path = Server.MapPath();
        System.IO.FileInfo file = new System.IO.FileInfo(strPath);
        if (file.Exists)
        {
            Response.Clear();
            Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/octet-stream";
            Response.WriteFile(file.FullName);
            Response.End();
        }
        else
        {
            Response.Write("This file does not exist.");
        }



    }
    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
       
        ddlhCountryCode.SelectedIndex = ddlhCountryCode.Items.IndexOf(ddlhCountryCode.Items.FindByValue(Convert.ToString(ddlCountry.SelectedValue)));
        string temp = (string)ddlhCountryCode.Items[ddlhCountryCode.SelectedIndex].Text;
        ddlMCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByValue(temp));
        ddlWCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByValue(temp));
        ddlOCountryCode.SelectedIndex = ddlMCountryCode.Items.IndexOf(ddlMCountryCode.Items.FindByValue(temp));



     
    }
    protected void gvCompanyDetails_RowEditing(object sender, GridViewEditEventArgs e)
    {

    }
    protected void ddlAccreType_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void gvUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        tb = (DataTable)ViewState["companydetails"];
        tb.Rows[e.RowIndex].Delete();
        tb.AcceptChanges();
        

        gvUser.DataSource = tb;
        gvUser.DataBind();
     //   foreach(DataRow dr in )
        ViewState["companydetails"] = tb;
    }

    protected void rdbUploadpic_CheckedChanged(object sender, EventArgs e)
    {
        if (rdbUploadpic1.Checked == true)
        {
            Response.Write("");
            fuUploadPic.Enabled = true;
         //   imageupload.Visible = true;

        }
        else
        {
            Response.Write("");
            fuUploadPic.Enabled = false;
          
         ///   imageupload.Visible = false;
        }
    }
    protected void rdbUploadResume_CheckedChanged(object sender, EventArgs e)
    {
        if (rdbResume1.Checked)
        { fuResume.Enabled = true; }
        else
            fuResume.Enabled = false;
    }
    protected void mvwCandidateReg_ActiveViewChanged(object sender, EventArgs e)
    {
        mainMenu.Items[0].Text = mainMenu.Items[0].Text.RemoveHTMLTags();
        mainMenu.Items[1].Text = mainMenu.Items[1].Text.RemoveHTMLTags();
        mainMenu.Items[2].Text = mainMenu.Items[2].Text.RemoveHTMLTags();
        mainMenu.Items[3].Text = mainMenu.Items[3].Text.RemoveHTMLTags();
        
        switch (mvwCandidateReg.ActiveViewIndex)
        {
            case 0:
                mainMenu.Items[0].Text = "<b><font color='blue'>" + mainMenu.Items[0].Text + "</font></b>";
                break;
            case 1:
                mainMenu.Items[1].Text = "<b><font color='blue'>" + mainMenu.Items[1].Text + "</font></b>";
                break;
            case 2:
                mainMenu.Items[2].Text = "<b><font color='blue'>" + mainMenu.Items[2].Text + "</font></b>";
                break;
            case 3:
                mainMenu.Items[3].Text = "<b><font color='blue'>" + mainMenu.Items[3].Text + "</font></b>";
                break;
           

        }
    }
    protected void gvUser_SelectedIndexChanged(object sender, EventArgs e)
    {
      //  string CompanyId = gvAddWorkExp.SelectedRow.Cells[0].Text;
        string txtCompName = gvUser.SelectedRow.Cells[1].Text;
        txtCompanyName.Text = txtCompName.Replace("amp;", "");
        ViewState["CompanyNamevalidation"] = txtCompName;
       
        string txtTypeOfComp = gvUser.SelectedRow.Cells[2].Text;
        TxtTypeOfCompany.Text = txtTypeOfComp.Replace("amp;", "");
        string txtCurrentRo = gvUser.SelectedRow.Cells[3].Text;
        txtCurrentRole.Text = txtCurrentRo.Replace("amp;", "");

        ddlNoYearCurrentRole.SelectedValue = ddlNoYearCurrentRole.Items.FindByText(gvUser.SelectedRow.Cells[4].Text).Value;
        ddlNoModeratorYearExp.SelectedValue = ddlNoModeratorYearExp.Items.FindByText(gvUser.SelectedRow.Cells[5].Text).Value;
        ddlRLExperience.SelectedValue = ddlRLExperience.Items.FindByText(gvUser.SelectedRow.Cells[6].Text).Value;
        string strtxtRemark = gvUser.SelectedRow.Cells[7].Text;
        txtRemark.Text = strtxtRemark.Replace("&nbsp;", "");
        //txtRemark.Text = gvUser.SelectedRow.Cells[7].Text;

        divUpdateButtons.Visible = true;
        btnAddWorkExp.Visible = false;

        //string data = Convert.ToString(gvAddWorkExp.SelectedRow.Cells[0].Text);
        //ViewState["vwResumeCmyID"] = data;
        int rowIndex = gvUser.SelectedIndex;

        string strValue = gvUser.DataKeys[rowIndex].Value.ToString();

        ViewState["vwResumeCmyID"] = strValue;
        // txtCompanyName.Focus();
        txtRemark.Focus();
        btnNext.Enabled = false;
        btnPervious.Enabled = false;
        gvUser.Enabled = false;
    }

    protected void BtnUpdateWorkExp_Click(object sender, EventArgs e)
    {

        int intTOtalExp = Convert.ToInt32(ddlNoYearCurrentRole.SelectedValue.Trim());
        int intModExp = Convert.ToInt32(ddlNoModeratorYearExp.SelectedValue.Trim());
        int intRLExp = Convert.ToInt32(ddlRLExperience.SelectedValue.Trim());
        //int intModRLExp=(intModExp+intRLExp);

        if (intTOtalExp >= intModExp && intTOtalExp >= intRLExp)
        {
            if (Page.IsValid == true)
            {

                //Add wrok experience
                AddEditedWorkExperience(txtCompanyName.Text.Trim(), TxtTypeOfCompany.Text.Trim(), txtCurrentRole.Text.Trim(), ddlNoYearCurrentRole.SelectedValue.Trim(), ddlNoModeratorYearExp.SelectedValue.Trim(), ddlRLExperience.SelectedValue.Trim(), txtRemark.Text.Trim());
                BindWorkExperience();
                ClearDataWorkExperience();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Work Experience Edited Successfully.');", true);
                divUpdateButtons.Visible = false;
                btnAddWorkExp.Visible = true;
                ViewState["vwResumeCmyID"] = null;
                ViewState["CompanyNamevalidation"] = null;
                btnNext.Enabled = true;
                btnPervious.Enabled = true;
                gvUser.Enabled = true;
            }

        }
        else
        {
            if (intTOtalExp <= intModExp && intTOtalExp <= intRLExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Research Lead Experience & Moderator Experience Years.";

            }
            else if (intTOtalExp <= intModExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Moderator Experience Years.";
            }
            else if (intTOtalExp <= intRLExp)
            {
                lblTotExpRLMod.Text = "Company Experience Year Less than Research Lead Experience.";
            }

            //args.IsValid = false;
            //ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('company experience less than Research Lead Experience & Moderator Experience.');", true);
        }
    }
    protected void BtnCancelRecord_Click(object sender, EventArgs e)
    {
        divUpdateButtons.Visible = false;
        btnAddWorkExp.Visible = true;
        ClearDataWorkExperience();
        btnNext.Enabled = true;
        btnPervious.Enabled = true;
        gvUser.Enabled = true;
    }

    private void AddEditedWorkExperience(string strCompnayName, string strTypeOfCompany, string strCurrentRole, string strNoYearCurrentRole, string strNOModeratorYearExp, string strNoRLExperience, string strRemarks)
    {
        DataTable dtWorkExp;



        dtWorkExp = (DataTable)ViewState["companydetails"];


        string resumecompanyId = Convert.ToString(ViewState["vwResumeCmyID"]);

        foreach (DataRow dr in dtWorkExp.Rows)
        {
            if (Convert.ToString(dr["CandidateCompanyID"]) == resumecompanyId)
            {
                dr["CompanyName"] = strCompnayName;
                dr["TypeOfCompany"] = strTypeOfCompany;
                dr["RoleInCompany"] = strCurrentRole;
                dr["NumberOfYearRole"] = strNoYearCurrentRole;
                dr["NumberOfYearModeratorRole"] = strNOModeratorYearExp;
                dr["NumberOfYearResearchRole"] = strNoRLExperience;
                dr["Remarks"] = strRemarks;
            }
        }
        dtWorkExp.AcceptChanges();
        gvUser.DataSource = dtWorkExp;
        gvUser.DataBind();
        ViewState["companydetails"] = dtWorkExp;





        //var querySum = (from qs in dtWorkExp.AsEnumerable()
        //                where qs.Field<string>("CompanyName") == strCompnayName
        //                select qs).Count();

        //if (querySum <= 0)
        //{
        //   // dtWorkExp.Rows.Add(drWorkExp);
        //    ViewState["dtWorkExp"] = dtWorkExp;
        //}
        //else
        //{
        //    Response.Write("The Record already exists in the table");
        //}
    }
    private void ClearDataWorkExperience()
    {
        txtCompanyName.Text = "";
        txtCurrentRole.Text = "";
        TxtTypeOfCompany.Text = "";
        ddlNoYearCurrentRole.SelectedIndex = 0;
        ddlNoModeratorYearExp.SelectedIndex = 0;
        ddlRLExperience.SelectedIndex = 0;
        lblTotExpRLMod.Text = "";
        txtRemark.Text = "";
    }
}

